/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scheduler.fixtures;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import se392.ateam2006.meetingmgmt.MeetingCandidate;
import se392.ateam2006.meetingmgmt.MeetingMgmtRemote;
import se392.ateam2006.resourcemgmt.room.RoomEntity;
import se392.ateam2006.meetingmgmt.meeting.StartTimeShell;

/**
 *
 * @author Caroline
 */
public class CalculateDateTimeVenueForMeeting extends fit.RowFixture {

    private MeetingMgmtRemote meetingManage;
    private String meetingId;

    public CalculateDateTimeVenueForMeeting(MeetingMgmtRemote meetingManage, String meetingId) {
        this.meetingManage = meetingManage;
        this.meetingId = meetingId;
    }

//    public void resolveTime() {
//        MeetingTimeResolutionUtility mtr = new MeetingTimeResolutionUtility();
//        Duration duration = meetingManage.findMeetingById(meetingId).getDuration();
//        int durationInMinutes = calcDuartion(duration);
//        mtr.resolveTimes(durationInMinutes, meetingId, meetingManage);
//    }
//
//    public int calcDuartion(Duration duration) {
//        int durationInMinutes = duration.getDays() * 24 * 60;
//        durationInMinutes += duration.getHours() * 60;
//        durationInMinutes += duration.getMins();
//        return durationInMinutes;
//    }
//
    private String extractVenue(RoomEntity room) {
        if (room == null || room.getRoomID() == null) {
            return "";
        } else {
            return room.getRoomID();
        }
    }

    @Override
    public Object[] query() throws Exception {
        Collection<MeetingCandidate> meetingStartTimes = meetingManage.resolveMeetingTime(meetingId);
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd kk:mm");
        ArrayList startTimes = new ArrayList();
        if (null != meetingStartTimes) {
            for (MeetingCandidate mc : meetingStartTimes) {
                for(RoomEntity re : mc.getPossibleRooms())
                    startTimes.add(new CalculateMeetingShell(
                        format.format(mc.getStart().getTime()),
                        this.extractVenue(re)
                    ));
            }
        }
        return startTimes.toArray();
    }

    @Override
    public Class getTargetClass() {
        return CalculateMeetingShell.class;
    }
}
